import { Component, OnInit, ViewChild } from '@angular/core';

@Component({
  selector: 'app-news',
  templateUrl: './news.component.html',
  styleUrls: ['./news.component.css']
})
export class NewsComponent implements OnInit {


  //获取dom结点
  @ViewChild('myBox') myBox:any; // dom结点获取以后赋值给了myBox
  //获取一个组件
  @ViewChild('header') header:any;

  constructor() { }

  ngOnInit(): void {
  }

  //获取dom结点
  ngAfterViewInit(): void {
    //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
    //Add 'implements AfterViewInit' to the class.
    console.log(this.myBox.nativeElement);
    this.myBox.nativeElement.style.width='200px';
    this.myBox.nativeElement.style.height='100px';
    this.myBox.nativeElement.style.background='red';
    //调用子组件里面的方法
    // this.header.run();
  }
  getChildRun(){
    this.header.run();

  }

}
